package org.giovanolli.mumi.util;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * The Class ReflectionUtils.
 */
public abstract class ReflectionUtils {

	/**
	 * Resolve collection properties.
	 * 
	 * @param type
	 *            the type
	 * @return the list
	 */
	public static List<String> resolveCollectionProperties(Class<?> type) {
		List<String> ret = new ArrayList<String>();
		try {
			BeanInfo beanInfo = Introspector.getBeanInfo(type);
			for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
				if (Collection.class.isAssignableFrom(pd.getPropertyType()))
					ret.add(pd.getName());
			}
		} catch (IntrospectionException e) {
			e.printStackTrace();
		}
		return ret;
	}
}
